package com.fare.taluo.web.action;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Hashtable;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import javax.annotation.Resource;
import javax.inject.Inject;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.xalan.lib.sql.QueryParameter;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.common.remote.ftp.FtpConfig;
import com.common.remote.ftp.FtpTransferException;
import com.common.remote.sftp.SFtpFileTransferClient;
import com.fare.taluo.BaseFdcAction;
import com.fare.taluo.application.CaptureDataExportApplication;
import com.fare.taluo.application.ExcelInfoApplication;
import com.fare.taluo.application.plane.channel.SourceApplication;
import com.fare.taluo.conf.system.DefaultPropertiesLoader;
import com.fare.taluo.util.DateUtils;
import com.fare.taluo.util.JsonUtil;
import com.fare.taluo.vo.core.ExcelInfoVO;
import com.fare.taluo.vo.core.SourceEntityVO;
import com.fare.util.ReportProperties;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

@SuppressWarnings("serial")
@Controller("excelInfoAction")
@Scope("prototype")
@Namespace("/")
public class ExcelInfoAction extends BaseFdcAction {

	@Resource(name = "captureDataExportApplicationImpl")
	private CaptureDataExportApplication captureDataExportApplication;

	@Inject
	private ExcelInfoApplication excelInfoApplication;

	@Resource(name = "sourceApplication")
	private SourceApplication sourceApplication;

	private List<ExcelInfoVO> listVo;

	private String message;// 提示信息

	private List<SourceEntityVO> sourceLists;

	private String deptCode;

	private String dateForExcel;

	private ExcelInfoVO excelInfoVO;

	public String toDownload() {
		returnPageURL = "/fare/excelInfoDownload.jsp";
		return "dispatcher";

	}
	
	//通过后台action传入页面到iframe
	public void returnHtmlIframe() throws IOException{
		//先在后台进行一次登录（写入账号，密码），返回状态；jsp再次访问
		//ftp:ftpuser1:ftpuser1@112.124.29.224
		JSONArray ja = new JSONArray();
		String userName="ftpuser1";
		String pass="ftpuser1";
		String url="115.29.214.16";//"112.124.29.224";
		String urls="ftp://"+userName+":"+pass+"@"+url;
		
	   URL u = new URL(urls.toString() );
	   URLConnection urlconn = u.openConnection(); 
	   Object ob=urlconn.getContent();
	   String data[]=new String[2];
	   if(ob.toString() !=null){
		   ja.add("{\"status\":\"SUCCESS\"}");
		   ja.add("{\"url\":\""+urls+"\"}");
	   }
//	   response.getWriter().print(data);
	   super.toJSONOut(ja.toString());
	   
	}
	
	//判断是否存在元数据
	public void isExit() {
		String codeId = request.getParameter("codeId");
		String timeType = request.getParameter("timeType");
		timeType = timeType.replace("-", "").replace("_", "");
		List<ExcelInfoVO> list = excelInfoApplication.findBycodeAndTime(codeId,
				timeType);
		String data = "false";
		if (list != null && list.size() > 0) {
			data = "true";
		}
		try {
			response.getWriter().write(data);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public String findExcel() throws Exception {
		if (dateForExcel != null) {
			dateForExcel = dateForExcel.replace("-", "");
		}
		excelInfoVO = new ExcelInfoVO();
		// SourceVo sourceVo
		// =departmentServiceImpl.jdbcGetSourceByhbaseKey(deptCode);

			SourceEntityVO sourceVo = sourceApplication.findByHbaseKey(deptCode);
			excelInfoVO.setCode(sourceVo.getHbaseKey());
			excelInfoVO.setName(sourceVo.getName());
			excelInfoVO.setCodeName(sourceVo.getName());
			excelInfoVO.setDateType("all");

		listVo = excelInfoApplication.findBycode(deptCode, dateForExcel);
		if (listVo == null || listVo.isEmpty() || listVo.size() == 0) {// 对查询不到的结果进行提示
			message = "对不起,没有相关数据";
			request.setAttribute(message, message);
		} else {
			for (ExcelInfoVO vo : listVo) {
				SourceEntityVO dept = sourceApplication
						.findByHbaseKey(vo.getCode());
				Date date = DateUtils.strToDate(vo.getDateType(), "yyyyMMddHH");
				String dateType = DateUtils.dateToStr(date, "yyyy-MM-dd_HH");
				vo.setCodeName(dept.getName());
				vo.setDateType(dateType);
			}
		}
		sourceLists = sourceApplication.findAllSourceEntity();
		returnPageURL = "/fare/excelInfoDownload.jsp";

		return "dispatcher";
	}

	//下载元数据操作
	public void download() {
		String codeId = request.getParameter("codeId");
		String timeType = request.getParameter("timeType");
		timeType = timeType.replace("-", "").replace("_", "");
		List<ExcelInfoVO> list = excelInfoApplication.findBycodeAndTime(codeId,
				timeType);
		ServletOutputStream out = null;
		SFtpFileTransferClient sftpClient = null;
		ReportProperties rp;
		InputStream is = null;
		List<File> files = new ArrayList<File>();
		try {

			rp = ReportProperties.getInstance();
			FtpConfig config = new FtpConfig(rp.getAddress(), rp.getPort(),
					rp.getUserName(), rp.getPassword());
			sftpClient = new SFtpFileTransferClient(config);
			boolean flag = false;
			try {
				flag = sftpClient.connect();
			} catch (FtpTransferException e) {
			}
			if (!flag) {
				throw new Exception("connect sftp fail");
			}
			String fileName = null;
			for (ExcelInfoVO vo : list) {
				// 文件地址
				String src = rp.getPath() + vo.getPath();
				SourceEntityVO dept = sourceApplication
						.findByHbaseKey(vo.getCode());
				vo.setCodeName(dept.getName());
				Date date = DateUtils.strToDate(vo.getDateType(), "yyyyMMddHH");
				String dateType = DateUtils.dateToStr(date, "yyyy-MM-dd_HH");
				fileName = dateType + ".zip";
				// if(codeId!=null && !"".equals(codeId)){
				fileName = vo.getCodeName() + "(" + dateType + ").zip";
				// }
				fileName = fileName.replace(" ", "_");
				is = sftpClient.downloadStream(src);
				out = response.getOutputStream();
				// response.reset();
				// 设置输出的格式
				// response.setContentType("application/pdf;charset=UTF-8");
				response.setContentType("application/octet-stream;charset=UTF-8");
				if (request.getHeader("User-Agent").toLowerCase()
						.indexOf("firefox") > 0) {
					fileName = new String(fileName.getBytes("UTF-8"),
							"ISO8859-1");// firefox浏览器
				} else {
					fileName = URLEncoder.encode(fileName, "UTF-8");// 其他浏览器
				}
				response.setHeader("Content-Disposition",
						"attachment; filename=" + fileName);
				// 循环取出流中的数据
				byte[] b = new byte[1024 * 1024];
				int len;

				while ((len = is.read(b)) > 0) {
					out.write(b, 0, len);
				}

				out.flush();
				// is.close();
				// out.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (out != null) {
					out.close();
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {

				if (is != null) {
					is.close();
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if (sftpClient != null) {
				sftpClient.disconnect();
			}
		}

	}

	//下载当天所有航空公司下的数据
	public void downLoadAll() throws Exception {
		String codeId = request.getParameter("codeId");
		String timeType = request.getParameter("timeType");
		timeType = timeType.replace("-", "").replace("_", "");
		List<ExcelInfoVO> list = excelInfoApplication.findBycodeAndTime(codeId,
				timeType);
		if (list != null) {
			ExcelInfoVO vo = list.get(0);
			downOneFile(vo);
		}
	}

	public void downOneFile(ExcelInfoVO vo) {
		ServletOutputStream out = null;
		SFtpFileTransferClient sftpClient = null;
		ReportProperties rp;
		InputStream is = null;
		try {
			rp = ReportProperties.getInstance();
			FtpConfig config = new FtpConfig(rp.getAddress(), rp.getPort(),
					rp.getUserName(), rp.getPassword());
			sftpClient = new SFtpFileTransferClient(config);
			boolean flag = false;
			try {
				flag = sftpClient.connect();
			} catch (FtpTransferException e) {
			}
			if (!flag) {
				throw new Exception("connect sftp fail");
			}
			String fileName = null;

			Date date = DateUtils.strToDate(vo.getDateType(), "yyyyMMddHH");
			String dateType = DateUtils.dateToStr(date, "yyyy-MM-dd HH");
			fileName = dateType + ".zip";
			// 文件地址
			String src = rp.getPath() + vo.getPath().substring(0, 20)
					+ fileName;
			fileName = fileName.replace(" ", "_");

			is = sftpClient.downloadStream(src);
			out = response.getOutputStream();
			// response.reset();
			// 设置输出的格式
			// response.setContentType("application/pdf;charset=UTF-8");
			// HttpServletResponse response =
			response.setContentType("application/octet-stream;charset=UTF-8");
			if (request.getHeader("User-Agent").toLowerCase()
					.indexOf("firefox") > 0) {
				fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");// firefox浏览器
			} else {
				fileName = URLEncoder.encode(fileName, "UTF-8");// 其他浏览器
			}
			response.setHeader("Content-Disposition", "attachment; filename="
					+ fileName);
			// 循环取出流中的数据

			byte[] b = new byte[1024 * 1024];
			int len;

			while ((len = is.read(b)) > 0) {
				out.write(b, 0, len);
			}
			out.flush();

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (out != null) {
					out.close();
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {

				if (is != null) {
					is.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (sftpClient != null) {
				sftpClient.disconnect();
			}
		}

	}

	public void excelAllDownload() throws Exception {

		String codeId = request.getParameter("codeId");
		SourceEntityVO sourceVo = sourceApplication
				.findByHbaseKey(codeId);
		List<ExcelInfoVO> lists = new ArrayList<ExcelInfoVO>();
		String zipName = "元数据.zip";
		if (sourceVo != null && sourceVo.getName() != null) {
			lists = excelInfoApplication.findBycode(sourceVo.getHbaseKey(),
					null);
			zipName = sourceVo.getName() + ".zip";
		} else {
			lists = excelInfoApplication.findAll();
		}
		List<File> files = new ArrayList<File>();
		if (lists != null && lists.size() > 0) {
			for (ExcelInfoVO vo : lists) {
				File downFile = new File(
						DefaultPropertiesLoader.getAppExcelFilePath()
								+ vo.getName() + ".xls");
				files.add(downFile);
			}
		}
		HttpServletResponse response = ServletActionContext.getResponse();
		try {
			response = downLoadFiles(files, response, zipName);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void excelDownload() {
		try {
			String codeId = request.getParameter("codeId");
			String timeType = request.getParameter("timeType");
			timeType = timeType.replace("-", "").replace("_", "");
			List<ExcelInfoVO> list = excelInfoApplication.findBycodeAndTime(
					codeId, timeType);
			List<File> files = new ArrayList<File>();
			for (ExcelInfoVO vo : list) {
				File downFile = new File(
						DefaultPropertiesLoader.getAppExcelFilePath()
								+ vo.getName() + ".xls");
				files.add(downFile);
			}
			ExcelInfoVO vo = list.get(0);
			SourceEntityVO dept = sourceApplication.findByHbaseKey(vo
					.getCode());
			vo.setCodeName(dept.getName());
			Date date = DateUtils.strToDate(vo.getDateType(), "yyyyMMddHH");
			String dateType = DateUtils.dateToStr(date, "yyyy-MM-dd_HH");
			String zipName = dateType + ".zip";
			if (codeId != null && !"".equals(codeId)) {
				zipName = vo.getCodeName() + "(" + dateType + ").zip";
			}
			zipName = zipName.replace(" ", "_");
			HttpServletResponse response = ServletActionContext.getResponse();

			response = downLoadFiles(files, response, zipName);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	// 文件打包下载
	private HttpServletResponse downLoadFiles(List<File> files,
			HttpServletResponse response, String zipName) throws Exception {
		try {
			/**
			 * 这个集合就是你想要打包的所有文件， 这里假设已经准备好了所要打包的文件
			 */
			// List<File> files = new ArrayList<File>();

			/**
			 * 创建一个临时压缩文件， 我们会把文件流全部注入到这个文件中 这里的文件你可以自定义是.rar还是.zip
			 */
			File file = new File(DefaultPropertiesLoader.getAppExcelFilePath()
					+ zipName);
			if (!file.exists()) {
				file.createNewFile();
			}
			response.reset();

			// response.getWriter()
			// 创建文件输出流
			FileOutputStream fous = new FileOutputStream(file);
			/**
			 * 打包的方法我们会用到ZipOutputStream这样一个输出流, 所以这里我们把输出流转换一下
			 */
			// org.apache.tools.zip.ZipOutputStream zipOut
			// = new org.apache.tools.zip.ZipOutputStream(fous);
			ZipOutputStream zipOut = new ZipOutputStream(fous);
			/**
			 * 这个方法接受的就是一个所要打包文件的集合， 还有一个ZipOutputStream
			 */
			zipFile(files, zipOut);
			zipOut.close();
			fous.close();
			return downloadZip(file, response, zipName);
		} catch (Exception e) {
			e.printStackTrace();
		}
		/**
		 * 直到文件的打包已经成功了， 文件的打包过程被我封装在FileUtil.zipFile这个静态方法中，
		 * 稍后会呈现出来，接下来的就是往客户端写数据了
		 */
		// OutputStream out = response.getOutputStream();

		return response;
	}

	/**
	 * 把接受的全部文件打成压缩包
	 * 
	 * @param List
	 *            <File>;
	 * @param org
	 *            .apache.tools.zip.ZipOutputStream
	 */
	private void zipFile(List files, ZipOutputStream outputStream) {
		int size = files.size();
		for (int i = 0; i < size; i++) {
			File file = (File) files.get(i);
			zipFile(file, outputStream);
		}
	}

	/**
	 * 根据输入的文件与输出流对文件进行打包
	 * 
	 * @param File
	 * @param org
	 *            .apache.tools.zip.ZipOutputStream
	 */
	private void zipFile(File inputFile, ZipOutputStream ouputStream) {
		try {
			if (inputFile.exists()) {
				/**
				 * 如果是目录的话这里是不采取操作的， 至于目录的打包正在研究中
				 */
				if (inputFile.isFile()) {
					FileInputStream IN = new FileInputStream(inputFile);
					BufferedInputStream bins = new BufferedInputStream(IN, 512);
					// org.apache.tools.zip.ZipEntry
					ZipEntry entry = new ZipEntry(inputFile.getName());
					ouputStream.putNextEntry(entry);
					// 向压缩文件中输出数据
					int nNumber;
					byte[] buffer = new byte[512];
					while ((nNumber = bins.read(buffer)) != -1) {
						ouputStream.write(buffer, 0, nNumber);
					}
					// 关闭创建的流对象
					bins.close();
					IN.close();
				} else {
					try {
						File[] files = inputFile.listFiles();
						for (int i = 0; i < files.length; i++) {
							zipFile(files[i], ouputStream);
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private HttpServletResponse downloadZip(File file,
			HttpServletResponse response, String zipName) {
		try {
			// 以流的形式下载文件。
			InputStream fis = new BufferedInputStream(new FileInputStream(
					file.getPath()));
			byte[] buffer = new byte[fis.available()];
			fis.read(buffer);
			fis.close();
			// 清空response
			response.reset();

			OutputStream toClient = new BufferedOutputStream(
					response.getOutputStream());
			response.setContentType("application/octet-stream");
			// response.setHeader("Content-Disposition", "attachment;filename="
			// + file.getName());
			if (request.getHeader("User-Agent").toLowerCase()
					.indexOf("firefox") > 0) {
				zipName = new String(zipName.getBytes("UTF-8"), "ISO8859-1");// firefox浏览器
			} else {
				zipName = URLEncoder.encode(zipName, "UTF-8");// 其他浏览器
			}
			response.setHeader("Content-Disposition", "attachment; filename="
					+ zipName);// 设定输出文件头
			toClient.write(buffer);
			toClient.flush();
			toClient.close();
		} catch (IOException ex) {
			ex.printStackTrace();
		} finally {
			try {
				File f = new File(file.getPath());
				f.delete();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return response;
	}

	/**
	 * 手动生成excel
	 * 
	 * @throws Exception
	 */
	public void excelByTime() throws Exception {

		String timeType = request.getParameter("timeType");
		String time = timeType.replace("-", "").replace(" ", "");
		String year = time.substring(0, 4);
		String month = time.substring(4, 6);
		String day = time.substring(6, 8);
		String hour = time.substring(8, 10);
		SimpleDateFormat sdfType = new SimpleDateFormat("yyyy-MM-dd HH");
		List<SourceEntityVO> list = sourceApplication.findAllSourceEntity();
		// 取得配置文件实例
		ReportProperties rp = ReportProperties.getInstance();
		// ftp连接配置
		FtpConfig config = new FtpConfig(rp.getAddress(), rp.getPort(),
				rp.getUserName(), rp.getPassword());
		SFtpFileTransferClient sftpClient = new SFtpFileTransferClient(config);
		String dir = rp.getPath() + "excel" + "/" + year + "-" + month + "/"
				+ day + "/" + hour;// 文件目录路径
		InputStream in = null;
		File allFile = new File(DefaultPropertiesLoader.getAppExcelFilePath()
				+ timeType + ".zip");
		FileOutputStream fousAll = new FileOutputStream(allFile);
		ZipOutputStream zipOutAll = new ZipOutputStream(fousAll);
		boolean filebind = false;
		try {
			Date date = sdfType.parse(timeType);
			for (SourceEntityVO sourceVo : list) {
				String code = sourceVo.getHbaseKey();
				String fileName = sourceVo.getName() + '(' + timeType + ')';
				List<ExcelInfoVO> listvo = excelInfoApplication
						.findBycodeAndTime(code, time);
				boolean flag = sftpClient.connect();
				if (listvo != null && listvo.size() > 0) {
					for (ExcelInfoVO vo : listvo) {
						if (sftpClient
								.isFileExists(rp.getPath() + vo.getPath())) {
							boolean flagDel = sftpClient.delete(rp.getPath()
									+ vo.getPath());
							if (flagDel&&flag) {
								excelInfoApplication.delete(vo);
							}
						} else {
							excelInfoApplication.delete(vo);
						}
					}
				}
				String result = captureDataExportApplication.exportExcelByTime(
						date, code, fileName);

				// System.out.print(result);
				if ("nodata".equals(result)) {
					// status = "nodata";
				} else {

					/**
					 * 创建一个临时压缩文件， 我们会把文件流全部注入到这个文件中 这里的文件你可以自定义是.rar还是.zip
					 */
					File file = new File(
							DefaultPropertiesLoader.getAppExcelFilePath()
									+ code + '(' + timeType + ')' + ".zip");
					FileOutputStream fous = new FileOutputStream(file);
					/**
					 * 打包的方法我们会用到ZipOutputStream这样一个输出流, 所以这里我们把输出流转换一下
					 */
					ZipOutputStream zipOut = new ZipOutputStream(fous);
					/**
					 * 这个方法接受的就是一个所要打包文件的集合， 还有一个ZipOutputStream
					 */
					zipFile(new File(result), zipOut);
					zipFile(new File(result), zipOutAll);
					filebind = true;
					zipOut.close();
					fous.close();

					// 一级一级创建目录
					String[] dirs = dir.split("/");
					StringBuffer buffer = new StringBuffer();
					for (String d : dirs) {
						buffer.append(d + "/");
						// System.out.println(buffer.toString());
						if (!sftpClient.isDirectoryExists(buffer.toString())) {
							sftpClient.makeDirectory(buffer.toString());
						}
					}
					in = new FileInputStream(file);
					sftpClient.upload(in, dir + "/" + fileName + ".zip");
					ExcelInfoVO excelInfoVO = new ExcelInfoVO();
					excelInfoVO.setCode(code);
					excelInfoVO.setDateType(time);
					excelInfoVO.setName(fileName);
					excelInfoVO.setPath("excel" + "/" + year + "-" + month
							+ "/" + day + "/" + hour + "/" + fileName + ".zip");
					excelInfoVO.setUploadDate(new Date());
					excelInfoApplication.saveOrUpdate(excelInfoVO);
					in.close();
					file.delete();
					File f = new File(result);
					f.delete();
				}
			}
			if (filebind) {
				zipOutAll.close();
				in = new FileInputStream(allFile);
				sftpClient.upload(in, dir + "/" + timeType + ".zip");
				in.close();
				allFile.delete();
			}

		} catch (Exception e) {
			// log.error("处理任务出现异常", e);
			e.printStackTrace();
			System.out.print("Excel表生成出现异常");
		} finally {
			sftpClient.disconnect();
			try {
				if (in != null) {
					in.close();
				}
			} catch (Exception e) {
			}
		}
	}

	/**
	 * 手动删除Exel
	 */
	public void deleteExcel() {
		String timeType = request.getParameter("timeType");
		String codeId = request.getParameter("codeId");
		String time = timeType.replace("-", "").replace(" ", "");
		List<ExcelInfoVO> listvo = excelInfoApplication.findBycodeAndTime(
				codeId, time);
		ReportProperties rp;
		SFtpFileTransferClient sftpClient = null;
		try {
			rp = ReportProperties.getInstance();
			// ftp连接配置
			FtpConfig config = new FtpConfig(rp.getAddress(), rp.getPort(),
					rp.getUserName(), rp.getPassword());
			sftpClient = new SFtpFileTransferClient(config);
			sftpClient.connect();

			for (ExcelInfoVO vo : listvo) {
				if (sftpClient.isFileExists(rp.getPath() + vo.getPath())) {
					boolean flag = sftpClient.delete(rp.getPath()
							+ vo.getPath());
					if (flag) {
						excelInfoApplication.delete(vo);
					}
				} else {
					excelInfoApplication.delete(vo);
				}

				if (codeId == null || "".equals(codeId)) {
					Date date1 = DateUtils.strToDate(vo.getDateType(),
							"yyyyMMddHH");
					String dateType = DateUtils.dateToStr(date1,
							"yyyy-MM-dd HH");
					String fileDir = rp.getPath()
							+ vo.getPath().substring(0, 19);
					String fileName = rp.getPath()
							+ vo.getPath().substring(0, 20) + dateType + ".zip";
					if (sftpClient.isFileExists(fileName)) {
						sftpClient.delete(fileName);
					}
					if (sftpClient.isDirectoryExists(fileDir)) {
						if (sftpClient.list(fileDir) == null) {
							JSch jsch = new JSch();
							Session session = jsch
									.getSession(config.getUserName(),
											config.getFtpUrlorIp(),
											config.getFtpPort());
							session.setPassword(config.getPassword());
							Hashtable<String, String> config1 = new Hashtable<String, String>();
							config1.put("StrictHostKeyChecking", "no");
							session.setConfig(config1);

							session.connect();
							Channel channel = session.openChannel("sftp");
							channel.connect();
							ChannelSftp c = (ChannelSftp) channel;
							c.rmdir(fileDir);
							channel.disconnect();
						}
					}
				}

			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (sftpClient != null) {
				sftpClient.disconnect();
			}
		}
	}

	public List<ExcelInfoVO> getListVo() {
		return listVo;
	}

	public void setListVo(List<ExcelInfoVO> listVo) {
		this.listVo = listVo;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public List<SourceEntityVO> getSourceLists() {
		return sourceLists;
	}

	public void setSourceLists(List<SourceEntityVO> sourceLists) {
		this.sourceLists = sourceLists;
	}

	public String getDeptCode() {
		return deptCode;
	}

	public void setDeptCode(String deptCode) {
		this.deptCode = deptCode;
	}

	public String getDateForExcel() {
		return dateForExcel;
	}

	public void setDateForExcel(String dateForExcel) {
		this.dateForExcel = dateForExcel;
	}

	public ExcelInfoVO getExcelInfoVO() {
		return excelInfoVO;
	}

	public void setExcelInfoVO(ExcelInfoVO excelInfoVO) {
		this.excelInfoVO = excelInfoVO;
	}

	public static void main(String[] args) throws Exception {
		String userName="ftpuser1";
		String pass="ftpuser1";
		String url1="112.124.29.224";
		String urls="ftp://"+userName+":"+pass+"@"+url1;
		
		StringBuffer sb = new StringBuffer(); 
		

    } 
		
		
	
}
